USE [Rolodex]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[ContactCategory]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[ContactCategory](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[Name] [varchar](250) NOT NULL,
	[Description] [varchar](1500) NULL,
	[LastUpdateBy] [varchar](150) NOT NULL,
	[LastUpdateDateTime] [datetime] NOT NULL,
	[Deleted] [bit] NOT NULL CONSTRAINT [DF_ContactCategories_Deleted]  DEFAULT ((0)),
 CONSTRAINT [PK_ContactCategory] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Contact]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[Contact](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[CategoryID] [int] NOT NULL,
	[WorkgroupID] [uniqueidentifier] NOT NULL,
	[CompanyName] [varchar](150) NOT NULL,
	[Name] [varchar](250) NOT NULL,
	[Phone] [varchar](100) NOT NULL,
	[Email] [varchar](150) NOT NULL,
	[Website] [varchar](250) NULL,
	[AddressLine1] [varchar](250) NULL,
	[AddressLine2] [varchar](250) NULL,
	[City] [varchar](100) NULL,
	[State] [varchar](50) NULL,
	[Zip] [varchar](25) NULL,
	[Fax] [varchar](100) NULL,
	[LastUpdateBy] [varchar](150) NOT NULL,
	[LastUpdateDateTime] [datetime] NOT NULL,
	[Notes] [ntext] NULL,
	[Deleted] [bit] NOT NULL CONSTRAINT [DF_Contact_Deleted]  DEFAULT ((0)),
 CONSTRAINT [PK_Contact] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_Contact_ContactCategory]') AND type = 'F')
ALTER TABLE [dbo].[Contact]  WITH CHECK ADD  CONSTRAINT [FK_Contact_ContactCategory] FOREIGN KEY([CategoryID])
REFERENCES [dbo].[ContactCategory] ([ID])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Contact] CHECK CONSTRAINT [FK_Contact_ContactCategory]
